#!/bin/bash

SoftPath="/usr/local/share/applications/UpdateUserWithPuppet/"
mkdir -p $SoftPath 
mkdir -p $SoftPath"conf"

/usr/bin/wget http://gitlab.ihep.ac.cn/yanxf/ihep-module/raw/master/modules/localaccounts/tests/user_local.py -P $SoftPath

$SoftPath"user_local.py"

if [ "$?" -ne "0" ]
then
  echo "ERROR"
  echo 'Error ' |mail -s "Error in access mysql afs accounts database" zhengw@ihep.ac.cn,yanxf@ihep.ac.cn
else 
  puppet parser validate /tmp/accounts.pp
  if [ "$?" -ne "0" ]
  then
    echo 'Error ' |mail -s "Error create puppet afs accounts manifest" yanxf@ihep.ac.cn,zhengw@ihep.ac.cn
  else
    /bin/cp /tmp/accounts.pp /usr/local/share/applications/UpdateUserWithPuppet/conf/accounts.pp
  fi
fi

#zhengw
